﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using GlobalGameClasses;

namespace DrawableObjects
{
    /// <summary>
    /// This class represents the camera of the game. It calculates the view on the game.
    /// </summary>
    public class Camera 
    {
        public float distanceToStart
        {
            get;
            private set;
        }

        private Vector3 startPosition
        {
            get;
            set;
        }

	    public Vector3 position
	    {
		    get;
		    private set;
	    }

        public Vector3 position1
        {
            get;
            private set;
        }

        public Vector3 eyeVector
        {
            get;
            private set;
        }

	    public virtual Matrix viewMatrix
	    {
		    get;
		    set;
	    }

	    public Matrix projectionMatrix
	    {
		    get;
		    set;
	    }

        private float movingSpeed;

        /// <summary>
        /// Scrolls over the terrain.
        /// </summary>
	    public virtual void Update()
	    {
            Vector3 direction = Vector3.Multiply(viewMatrix.Forward, movingSpeed * GlobalGameValues.SPEEDFACTOR * (float)GlobalGameValues.Values.gameTime.ElapsedGameTime.TotalMilliseconds);
            position += direction;
            position1 += new Vector3(0, 0, movingSpeed * GlobalGameValues.SPEEDFACTOR * (float)GlobalGameValues.Values.gameTime.ElapsedGameTime.TotalMilliseconds);
            viewMatrix *= Matrix.CreateTranslation(direction);
            distanceToStart = Vector3.Distance(position, startPosition);
	    }

        public Camera(Vector3 position, Vector3 target)
            : this(position, target, 0f)
        {
        }

	    public Camera(Vector3 position, Vector3 target, float movingSpeed)
	    {
            this.position1 = position;
            this.position = position;
            this.eyeVector = Vector3.Normalize(position - target);
            this.startPosition = position;
            this.viewMatrix = Matrix.CreateLookAt(this.position, target, Vector3.Up);
            this.projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 16f / 9f, 0.1f,1000f);
            this.movingSpeed = movingSpeed;
            this.distanceToStart = 0;
	    }

    }
}

